const http = require('http')
const db = require('./db')


const server = http.createServer()
server.listen(8848,() => {
    console.log('服务器启动了','http://192.168.13.116:8848');
})
server.on('request',(requset,response) => {
    const {url,method} = requset
    let data ={}
    if (method.toLowerCase() === 'get') {
        if (url === '/api/students') {
            data = db.students()
        }else if (url === '/api/lucystar') {
            data = db.lucystar()
        }
    }
    response.setHeader('Content-Type','application/json;charset = utf-8')
    response.setHeader('Access-Control-Allow-Origin','*')
   response.end(JSON.stringify(data))
})
